<?php
namespace App\Http\Requests\Admin;
use Illuminate\Support\Facades\Hash;

class SetPasswordRequest extends FormRequest
{
    

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'old_password' => ['required', function($attribute, $value, $fail){
                if(!Hash::check($value, auth('admin')->user()->password)){
                    $fail('旧密码输入错误');
                }
            }],
            'password' => ['required'],
            'confirm_password' => [function($attribute, $value, $fail){
                if(request()->password != $value){
                    $fail('新密码与确认密码不一致');
                }
            }],
        ]; 
    }

    public function messages()
    {
        return [
            'old_password.required' => '旧密码不能为空',
            'password.required' => '新密码不能为空',
        ];
    }
}
